package com.toprs.business.controller

import com.toprs.base.result.Result
import com.toprs.business.entity.AppReport
import com.toprs.business.entity.ApplicationBase
import com.toprs.business.query.ReportQuery
import com.toprs.business.service.ReportService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.servlet.http.HttpServletResponse
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController


@RestController
@RequestMapping("/report")
@Tag(description = "填报模块", name = "填报模块")
class ReportController(val reportService: ReportService) {


    @PostMapping("/add")
    @Operation(summary = "填报")
    fun addReport(@Valid @RequestBody report: AppReport): Result<Unit> {
        reportService.addReport(report)
        return Result.successMsg("上报成功！")
    }

    @PostMapping("/query")
    @Operation(summary = "查询填报信息")
    fun queryReport(@Valid @RequestBody reportQuery: ReportQuery): Result<List<ApplicationBase>> {
        val list: List<ApplicationBase> = reportService.queryReport(reportQuery)
        return Result.success(list)
    }

    @PostMapping("/export-excel")
    @Operation(summary = "根据条件导出excel")
    fun exportExcel(@Valid @RequestBody reportQuery: ReportQuery, response: HttpServletResponse) {
        reportService.exportExcel(reportQuery, response)
    }

    @PostMapping("/export-excel-items")
    @Operation(summary = "根据结果导出excel")
    fun exportExcelItems(@Valid @RequestBody list: List<ApplicationBase>, response: HttpServletResponse) {
        reportService.exportExcelItems(list, response)
    }


}